package com.easyfun.healthmagicbox.comm.json;

import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import com.easyfun.healthmagicbox.pojo.DoctorAndSuggestion;

public class DoctorAndSugListJsonWrapper <T extends JsonWrapper> extends AbstractListJsonWrapper<T,DoctorAndSuggestion>{
	
	public DoctorAndSugListJsonWrapper()
	{
		
	}
	
	public DoctorAndSugListJsonWrapper(List<DoctorAndSuggestion> pps)
	{
		super(pps);
	}
	
	@Override
	public void deserializeFromObj(JSONObject obj) throws JSONException {
			DoctorAndSuggestionJsonWrapper<?> leafwrapper;
			try {
				leafwrapper = DoctorAndSuggestionJsonWrapper.getInstance(
						obj.getJSONObject("DoctorAndSuggestion")
						, DoctorAndSuggestionJsonWrapper.class);
				mpps.add(leafwrapper.getDataPojo());
			} catch (InstantiationException e) {
				e.printStackTrace();
				throw new JSONException(e.toString());
			} catch (IllegalAccessException e) {
				e.printStackTrace();
				throw new JSONException(e.toString());
			}

	}
	
	@Override
	public JSONObject serializeToObj() throws JSONException {
		JSONObject serializedObj = new JSONObject();

		int i = 0;
		for (DoctorAndSuggestion pp : mpps) {
			DoctorAndSuggestionJsonWrapper<T> leafwrapper = new DoctorAndSuggestionJsonWrapper<T>(
					pp);
			serializedObj.put(String.valueOf(i), leafwrapper.serialize());
			i++;
		}

		return serializedObj;
	}
	

}
